import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Lab2 extends java.applet.Applet implements Runnable,KeyListener, MouseListener   {
	String msg = "RUNNING STRING ";
	Thread t = null;
	Font fr, fc;
	Choice chBkColor;
	Choice chForColor;
	Color colors[] = { Color.WHITE, Color.BLACK, Color.BLUE, Color.GREEN,
			Color.RED };
	
	private int width = 80;
	private int height = 100;

	public void init() {
		
		System.out.print("init");
		fr = new Font("Dialog", Font.BOLD, 20);
		fc = new Font("Dialog", Font.BOLD, 10);
		chBkColor = new Choice();
		chBkColor.add("White");
		chBkColor.add("Black");
		chBkColor.add("Blue");
		chBkColor.add("Green");
		chBkColor.add("Red");
		chBkColor.setFont(fc);
		add(chBkColor);

		chForColor = new Choice();
		chForColor.add("White");
		chForColor.add("Black");
		chForColor.add("Blue");
		chForColor.add("Green");
		chForColor.add("Red");
		chForColor.setFont(fc);
		add(chForColor);

		

		setFont(fr);
		
	}

	public void start() {
		System.out.print("Start");
		t = new Thread(this);
		t.start();
	}

	public void run() {
		System.out.print("Run");
		char ch;
		for (;;) {
			try {
				repaint();
				Thread.sleep(100);
				ch = msg.charAt(0);
				msg = msg.substring(1, msg.length());
				msg += ch;
			} catch (InterruptedException e) {
			}
		}
	}

	public void paint(Graphics g) {
		Color c = colors[chBkColor.getSelectedIndex()];
		setBackground(c);
		c = colors[chForColor.getSelectedIndex()];
		setForeground(c);
		g.drawString(msg, width, height);

	}

	@Override
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
		requestFocus();
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}
}
